package com.vinjogames.util;

public class GameClock {
	
	private long mGameTime;
	private long mLastTick;
	private long mCurrentTime;
	
	private GameClock(){};

	private static class GameClockHolder {
		public static final GameClock instance = new GameClock();
	}

	public static GameClock getInstance(){
		return GameClockHolder.instance;
	}
	
	public void tick(){
		mCurrentTime = System.currentTimeMillis();
		if(mLastTick != 0){
			mGameTime += mCurrentTime - mLastTick;
			mLastTick = mCurrentTime;
		}
	}
	
	public long getTime(){
		tick();
		return mGameTime;
	}
	
	public void setTime(long time){
		this.mGameTime = time;
	}
	
	public void pause(){
		mLastTick = 0;
	}
	
	public void resume(){
		mLastTick = System.currentTimeMillis();
	}
}
